local CheckWidgetType = UI.CheckWidgetType
local CheckArgType = UI.CheckArgType
local CheckArgWidget = UI.CheckArgWidget
local MakeTypeSetter = UI.MakeTypeSetter

--[[ GameTooltip @FIXME ]]--
local GameTooltip = UI.NewWidgetType("GameTooltip", "Frame")
GameTooltip.parameters = {
	fontstrings = {},
	width = 0,
	content = nil,
}

function GameTooltip:Initialize(o)
	local t = UI.params[o]
	assert(t)
end

function GameTooltip.prototype:IsOwned(region)
	CheckWidgetType("GameTooltip:IsOwned", self, "GameTooltip")
	CheckArgWidget("GameTooltip:IsOwned", 2, "frame", "LayoutFrame", region)
	local t = UI.params[self]
	return region == t.owner
end

function GameTooltip.prototype:SetOwner(region)
	CheckWidgetType("GameTooltip:SetOwner", self, "GameTooltip")
	CheckArgWidget("GameTooltip:SetOwner", 2, "frame", "LayoutFrame", region)
	local t = UI.params[self]
	t.owner = region
end

function GameTooltip.prototype:GetOwner()
	CheckWidgetType("GameTooltip:GetOwner", self, "GameTooltip")
	local t = UI.params[self]
	return t.owner
end

function GameTooltip.prototype:AddFontStrings(fs1, fs2)
	CheckWidgetType("GameTooltip:AddFontStrings", self, "GameTooltip")
	CheckArgWidget("GameTooltip:AddFontStrings", 2, "fontstring", "FontString", fs1)
	if fs2 then
		CheckArgWidget("GameTooltip:AddFontStrings", 3, "fontstringright", "FontString", fs2)
	end
	local t = UI.params[self].fontstrings
	t[#t+1] = { left = fs1, right = fs2 }
end

MakeTypeSetter("GameTooltip", "SetPadding", "padding", "number")
MakeTypeSetter("GameTooltip", "SetMinimumWidth", "width", "number")

local function MakeTooltipFunction(name, type, getter)
	GameTooltip.prototype[name] = function (self, ...)
		local t = UI.params[self]
		t.content = {
			type = type,
			params = {...},
		}
		if getter then getter(t.content) end
	end
end

MakeTooltipFunction("SetSocketedItem", "item")

UI.RegisterScriptHandlers(GameTooltip,
	"OnTooltipSetDefaultAnchor", "OnTooltipAddMoney",
	"OnTooltipCleared", "OnTooltipSetUnit", "OnTooltipSetItem")
